//date1-date2
function difDaysDates(date1,date2){
    var vdate1 = date1.split("_")
    var vdate2 = date2.split("_")
    var dDate1 = new Date(vdate1[2],vdate1[1]-1,vdate1[0])
    var dDate2 = new Date(vdate2[2],vdate2[1]-1,vdate2[0])

    var dif = dDate1.getTime()-dDate2.getTime()
    return (dif/3600000)/24

}
function getHour() {
    var now = new Date();

    var minutes = now.getMinutes();

    if( minutes <= 9 )
        minutes = "0"+minutes;

    var out = now.getHours() + ":" + minutes;

    return out;
}

function getYear_Month() {

    var now = new Date();
    var month = now.getMonth()
    month++;
    if(month <= 9){
        month = "0" + month
    }
    var out = now.getFullYear()+ "_" + month;

    return out;
}
function getYearMonthDay(){
    var now = new Date();
    var month = now.getMonth()
    month++;
    if(month <= 9){
        month = "0" + month
    }
    var day = now.getDate()
    if(day <= 9){
        day = "0" + day
    }

    var out = now.getFullYear()+""+month+day;

    return out;
}

function dateToString(date1) {

    var month = date1.getMonth()
    month++;
    if(month <= 9){
        month = "0" + month
    }
    var day = date1.getDate()
    if(day <= 9){
        day = "0" + day
    }
    var seconds = date1.getSeconds()
    if(seconds <= 9){
        seconds = "0" + seconds
    }
    var out = day + "/" + month +"/" + date1.getFullYear() + " " + date1.getHours()+":"+date1.getMinutes()+":"+seconds;

    return out;
}

function getDay_Month_Year() {

    var now = new Date();
    var month = now.getMonth()
    month++;
    if(month <= 9){
        month = "0" + month
    }
    var day = now.getDate()
    if(day <= 9){
        day = "0" + day
    }

    var out = day + "_" + month +"_" + now.getFullYear();

    return out;
}
function twoDigits(s){
    if(s.length==1){
        return s = "0" + s
    }else{
        return s
    }
}
function dateToDescription(date){
    var numbers = date.split("_");
    var month = ""
    switch (numbers[1]){
    case "01": month = "Enero"
        break;
    case "02": month = "Febrero"
        break;
    case "03": month = "Marzo"
        break;
    case "04": month = "Abril"
        break;
    case "05": month = "Mayo"
        break;
    case "06": month = "Junio"
        break;
    case "07": month = "Julio"
        break;
    case "08": month = "Agosto"
        break;
    case "09": month = "Septiembre"
        break;
    case "10": month = "Octubre"
        break;
    case "11": month = "Noviembre"
        break;
    case "12": month = "Diciembre"
        break;

    }
    return numbers[0] + " de " + month + " de " +numbers[2]
}

function dayOfWeekDescription(day){
    var description = ""
    switch (day){
    case "1": description = "Lunes"
        break;
    case "2": description = "Martes"
        break;
    case "3": description = "Miércoles"
        break;
    case "4": description = "Jueves"
        break;
    case "5": description = "Viernes"
        break;
    case "6": description = "Sábado"
        break;
    case "7": description = "Domingo"
        break;

    }
    return description
}

function stringToDate(s) {
    var aux = s.split(" ")
    var aux2 = aux[0].split(":")
    var day = aux2[2]
    var month = aux2[1]
    var year = aux2[0]
    aux2 = aux[1].split(":")
    var hh = aux2[0]
    var mm = aux2[1]
    var ss = aux2[2]
//    console.log(month+"/"+day+"/"+year + " " + hh+":"+mm+":00");

    var date = new Date(month+"/"+day+"/"+year + " " + hh+":"+mm+":"+ss)
    return date;
}

function stringToDatepp(s) {
    var aux = s.split(" ")
    var aux2 = aux[0].split("-")
    var day = aux2[2]
    var month = aux2[1]
    var year = aux2[0]
    aux2 = aux[1].split(".")
    var hh = aux2[0]
    var mm = aux2[1]
    var ss = aux2[2]
//    console.log(month+"/"+day+"/"+year + " " + hh+":"+mm+":00");

    var date = new Date(month+"/"+day+"/"+year + " " + hh+":"+mm+":"+ss)
    return date;
}

function millisecondsToTimeFormat(int_m){
    var total_seconds = int_m/1000
    var minutes = Math.round(total_seconds/60)
    var seconds = total_seconds % 60
    seconds = Math.floor(seconds)
    return twoDigits(minutes.toString()) + ":" + twoDigits(seconds.toString())

}
